Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deriveaddresses RPC util method #14667

Merged
merged 1 commit into from Feb 7, 2019

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Nov 6, 2018

Usage:

bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
[
  "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
] // part of the BIP32 test vector

Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with scantxoutset as a poor mans wallet. Might be useful to test more complicated future descriptors.

To keep it as simple as possible it only supports descriptors that result in a single address, so no combo() and ranges.

As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don't need a chain or wallet context. However I prefer to leave that to another PR.

@laanwj
Copy link
Member

laanwj commented Nov 6, 2018

I know, this comes up every time—see for example #14476 (comment) —wasn't the idea to not add more pure-utility RPC calls?
We really need a clear stance on this.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 6, 2018

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@Sjors
Copy link
Member Author

Sjors commented Nov 6, 2018

I created an issue to discuss a tool that could replace pure utility RPC calls: #14671

src/rpc/misc.cpp Outdated Show resolved Hide resolved
src/rpc/misc.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, and after the discussion in the meeting this morning I think its worth adding.
utACK 9a55d5f

src/rpc/misc.cpp Outdated
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid descriptor"));
}
if (desc->IsRange()){
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Descriptor range not supported"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be easy enough to add support for picking a specific index from a ranged descriptor, is there a reason you chose to disallow it? Just add a second parameter which specifies the index.
EDIT: thinking about it, it would be just as easy to not use a ranged descriptor if we're only using a single key, don't worry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a weird anti-feature to me. I don't understand why you're adding extra complexity to the function just to prevent a range. If you only want one, you can still do so.

Copy link
Member Author

@Sjors Sjors Nov 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially did that to prevent extra complexity, but I've actually encountered a situation where allowing ranges would be very useful. Will change this to return an array.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sjors I assume that also includes allowing combo right? Sounds good 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meshcollider yes, no reason anymore to exclude combo()

@@ -3,3 +3,4 @@ New RPC methods

- `getnodeaddresses` returns peer addresses known to this node. It may be used to connect to nodes over TCP without using the DNS seeds.
- `listwalletdir` returns a list of wallets in the wallet directory which is configured with `-walletdir` parameter.
- `deriveaddress` returns the address corresponding to an [output descriptor](/doc/descriptors.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to belong in this file (the file is specific per PR).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listwalletdir was already hijacking that file, so I joined, but I can add a new one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case we could add them to the main file in the first place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the point of these extra files was mainly to prevent constant rebasing, which seemed mostly a result of different sections interfering, and less when you're just adding one line an existing entry. Though I'm not sure exactly what trips up git.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file was removed in master. Also, if another patch added a line in the meantime, git(hub) would also report a merge conflict.

@Sjors
Copy link
Member Author

Sjors commented Nov 19, 2018

Rebased. Result is now an array of addresses, so combo() and ranges can be used. Added range arguments.

@Sjors
Copy link
Member Author

Sjors commented Nov 19, 2018

Getting a rather cryptic linter error: @MarcoFalke?
schermafbeelding 2018-11-19 om 20 11 42

Update: #14718 was merged right before I pushed this. I rebased again and now I'm able to reproduce the linter error. It happens on master too.

@Sjors Sjors force-pushed the 2018/11/deriveaddress branch 2 times, most recently from c71cec5 to 684fdd1 Compare November 19, 2018 19:30
Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good

src/rpc/misc.cpp Outdated Show resolved Hide resolved
src/rpc/misc.cpp Outdated Show resolved Hide resolved
@Sjors Sjors force-pushed the 2018/11/deriveaddress branch 2 times, most recently from 24a58ab to 7eccdde Compare November 20, 2018 13:31
@Sjors Sjors changed the title Add deriveaddress RPC util method Add deriveaddresses RPC util method Nov 20, 2018
@Sjors
Copy link
Member Author

Sjors commented Nov 20, 2018

Rebased so CI works again. Renamed to plural deriveaddresses. Simplified the range arguments (must provide start and end).

@meshcollider
Copy link
Contributor

meshcollider commented Nov 22, 2018

utACK 82d2a8f

One last nit, I would add a comment about the default behavior of 0 for ranged descriptors if start and end aren't provided.

EDIT: Actually, I think the helptext needs to be switched to RPCHelpMan

@Sjors
Copy link
Member Author

Sjors commented Nov 23, 2018

@meshcollider alternatively I could make the range argument mandatory for ranged descriptors.

What do you mean with RPCHelpMan?

@meshcollider
Copy link
Contributor

@Sjors see #14726

@Sjors
Copy link
Member Author

Sjors commented Nov 27, 2018

Rebased due to #14726 and using RPCHelpMan now.

Range argument is now mandatory for ranged descriptors (typing 0 instead of * is trivial).

@maflcko
Copy link
Member

maflcko commented Jan 29, 2019

Indeed, we could pass a lambda into the RPCHelpMan to validate the value and use the passed in type to validate the type (and thus get rid of RPCTypeCheck completely)

@Sjors
Copy link
Member Author

Sjors commented Jan 29, 2019

Rebased due to somewhat inexplicable Travis failure.

src/rpc/misc.cpp Outdated Show resolved Hide resolved
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of non-blocking nits, tACK 5952838

src/rpc/misc.cpp Show resolved Hide resolved
src/rpc/misc.cpp Show resolved Hide resolved

bare_multisig_descriptor = "multi(1, tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/0, tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/1)"
assert_raises_rpc_error(-5, "Descriptor does not have a corresponding address", self.nodes[0].deriveaddresses, bare_multisig_descriptor)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add a wallet roundtrip test like:

wpkh_info = self.nodes[0].getaddressinfo(self.nodes[0].getnewaddress("", "bech32"))
# Trim the witness part of descriptor off, check pkh entry in wallet, match descriptor
pkh_desc = wpkh_info["desc"][1:]
pkh_addr = self.nodes[0].deriveaddresses(pkh_desc)
pkh_info = self.nodes[0].getaddressinfo(pkh_addr)
assert_equal(wpkh_info["hdkeypath"], pkh_info["hdkeypath"])
assert_equal(wpkh_info["pubkey"], pkh_info["pubkey"])

@meshcollider meshcollider merged commit 5952838 into bitcoin:master Feb 7, 2019
meshcollider added a commit that referenced this pull request Feb 7, 2019
5952838 [rpc] util: add deriveaddresses method (Sjors Provoost)

Pull request description:

  Usage:

  ```sh
  bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
  [
    "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
  ] // part of the BIP32 test vector
  ```

  Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with `scantxoutset` as a poor mans wallet. Might be useful to test more complicated future descriptors.

  ~To keep it as simple as possible it only supports descriptors that result in a single address, so no `combo()` and ranges.~

  As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don't need a chain or wallet context. However I prefer to leave that to another PR.

Tree-SHA512: b8e53db11a8fd87638cc98766270cc3be9adc4b3e5085798a6a4e2e6ad252bf6d2189346bbb2da72d04d13f7f1e80b5cb88e8039653bea1f150602a876ef7f34
@Sjors Sjors deleted the 2018/11/deriveaddress branch February 8, 2019 09:49
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 22, 2020
Summary: This is a backport of Core [[bitcoin/bitcoin#14667 | PR14667]]

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D6214
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Sep 15, 2021
5952838 [rpc] util: add deriveaddresses method (Sjors Provoost)

Pull request description:

  Usage:

  ```sh
  bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
  [
    "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
  ] // part of the BIP32 test vector
  ```

  Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with `scantxoutset` as a poor mans wallet. Might be useful to test more complicated future descriptors.

  ~To keep it as simple as possible it only supports descriptors that result in a single address, so no `combo()` and ranges.~

  As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don't need a chain or wallet context. However I prefer to leave that to another PR.

Tree-SHA512: b8e53db11a8fd87638cc98766270cc3be9adc4b3e5085798a6a4e2e6ad252bf6d2189346bbb2da72d04d13f7f1e80b5cb88e8039653bea1f150602a876ef7f34
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Sep 16, 2021
5952838 [rpc] util: add deriveaddresses method (Sjors Provoost)

Pull request description:

  Usage:

  ```sh
  bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
  [
    "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
  ] // part of the BIP32 test vector
  ```

  Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with `scantxoutset` as a poor mans wallet. Might be useful to test more complicated future descriptors.

  ~To keep it as simple as possible it only supports descriptors that result in a single address, so no `combo()` and ranges.~

  As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don't need a chain or wallet context. However I prefer to leave that to another PR.

Tree-SHA512: b8e53db11a8fd87638cc98766270cc3be9adc4b3e5085798a6a4e2e6ad252bf6d2189346bbb2da72d04d13f7f1e80b5cb88e8039653bea1f150602a876ef7f34
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Sep 20, 2021
5952838 [rpc] util: add deriveaddresses method (Sjors Provoost)

Pull request description:

  Usage:

  ```sh
  bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
  [
    "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
  ] // part of the BIP32 test vector
  ```

  Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with `scantxoutset` as a poor mans wallet. Might be useful to test more complicated future descriptors.

  ~To keep it as simple as possible it only supports descriptors that result in a single address, so no `combo()` and ranges.~

  As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don't need a chain or wallet context. However I prefer to leave that to another PR.

Tree-SHA512: b8e53db11a8fd87638cc98766270cc3be9adc4b3e5085798a6a4e2e6ad252bf6d2189346bbb2da72d04d13f7f1e80b5cb88e8039653bea1f150602a876ef7f34
kwvg added a commit to kwvg/dash that referenced this pull request Oct 12, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Oct 21, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Oct 25, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Oct 25, 2021
vijaydasmp pushed a commit to vijaydasmp/dash that referenced this pull request Oct 26, 2021
5952838 [rpc] util: add deriveaddresses method (Sjors Provoost)

Pull request description:

  Usage:

  ```sh
  bitcoin-cli deriveaddresses "wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/0)"
  [
    "bc1qg6ucjz7kgdedam7v5yarecy54uqw82yym06z3q"
  ] // part of the BIP32 test vector
  ```

  Avoids the need for external (BIP32) libraries to derive an address. Can be used in conjunction with `scantxoutset` as a poor mans wallet. Might be useful to test more complicated future descriptors.

  ~To keep it as simple as possible it only supports descriptors that result in a single address, so no `combo()` and ranges.~

  As discussed recently on IRC it might make sense to put this in a separate utility along with other descriptor and psbt utility functions which don't need a chain or wallet context. However I prefer to leave that to another PR.

Tree-SHA512: b8e53db11a8fd87638cc98766270cc3be9adc4b3e5085798a6a4e2e6ad252bf6d2189346bbb2da72d04d13f7f1e80b5cb88e8039653bea1f150602a876ef7f34
kwvg added a commit to kwvg/dash that referenced this pull request Oct 26, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Oct 26, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Oct 28, 2021
pravblockc pushed a commit to pravblockc/dash that referenced this pull request Nov 18, 2021
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet